<?php

require_once('classes/modeles/Gardes/Garde.php');
require_once('classes/controleurs/Structure.php');
require_once('lib/String.php');

/**
 * Description of Gardes
 *
 * @author ROCU Fabien
 */

class Gardes {

    public $array_garde_id;
    public $array_garde;

    function __construct() {

    }

    public function charger_Garde( $date, $centre_id ) {

        $this->charger_arrayGardeID_gardes($date, $centre_id);
        $this->charger_arrayGarde_gardes($date, $centre_id);

    }

    private function charger_arrayGardeID_gardes( $date, $centre_id ) {

        global $_mysql;

        $tmp = Array();

        $this->array_garde_id = $tmp;
    }

    private function charger_arrayGarde_gardes( $date, $centre_id ) {

        global $_mysql;

        $tmp = Array();

        $this->array_garde = $tmp;
    }

    public function creer_garde( $pompier_id, $garde_etat, $garde_date, $garde_heure_debut, $garde_heure_fin, $type_garde_id, $garde_mutualisation ) {
        $garde = new Garde();
        $garde->set_garde($pompier_id, $garde_etat, $garde_date, $garde_heure_debut, $garde_heure_fin, $type_garde_id, $garde_mutualisation);
        $id = $garde->sauvegarder_garde();
    }

    public function effacer_garde( $garde_id ) {
        $garde = new Garde();
        $garde->effacer_garde($garde_id);
    }

    public function modifierEtat_garde( $garde_id, $new_etat ) {
        $garde = new Garde();
        $garde->charger_garde($garde_id);
        $garde->setGarde_etat($garde_etat);
        $garde->sauvegarder_garde();
    }

    public function getPompierID_Date_Centre ( $date, $centre_id ) {

        global $_mysql;

        $return = Array();

        $structure = new Structure();
        $structure->charger_affectation_centre($centre_id);

        $string = new String();        

        try {
            $query = "SELECT pompier_id FROM garde WHERE garde_date = $date AND pompier_id IN (" . $string->ArrayToString($structure->array_affectation_centre) . ");";
            if ( Config::$debugSQL ) echo "<br />" . $query . "<br />";
            $result = $_mysql->query($query);

            $i = 0;

            if ( $_mysql->num_rows($result) > 0 ) {
                $val = $_mysql->fetch_array($result);

                $return[$i] = $val['pompier_id'];
                $i++;
            }
        }
        catch (SQLException $sqle) {
            throw $sqle;
        }
            
    }

    /* *********************************************** */
    /* ************   Statistiques    **************** */
    /* *********************************************** */

    // TODO FRO Statistiques

}
?>
